package com.spacewiz13.algorithm.string;

import java.util.Queue;
import java.util.Stack;

/**
 * 反转字符串。
 * Given s = "the sky is blue",
	return "blue is sky the".
 * @author David
 *
 */
public class ReverseWords {

	public static void main(String[] args){
		String s= "the sky is blue";
		
		Stack word = new Stack();
		Stack sentence = new Stack();
		if(s!=null){
			for(int i=0;i<s.length();i++){
				char c = s.charAt(i);
				if(c == ' '){
					while(!word.isEmpty()){
						sentence.push(word.pop());
					}
					sentence.push(' ');

				}else{
					word.push(s.charAt(i));
				}
				if(i==s.length()-1){
					if(c != ' '){
						while(!word.isEmpty()){
							sentence.push(word.pop());
						}
					}
				}

			}
		}

		
		while(!sentence.isEmpty()){
			System.out.print(sentence.pop());
		}
		
	}
	
}
